-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Implement declarative (macro_rules!
) derive macros (RFC 3698)
#145208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
(Removing T-clippy and T-rustdoc, because the two commits specific to this PR don't touch them.) |
This comment has been minimized.
This comment has been minimized.
(Marking as "waiting on review" because I'm seeking help with the test failure here.) |
This comment was marked as resolved.
This comment was marked as resolved.
52710b2
to
17f6d0a
Compare
This comment was marked as outdated.
This comment was marked as outdated.
17f6d0a
to
75f119a
Compare
This comment has been minimized.
This comment has been minimized.
(Marking for review now that 145153 is queued.) |
(I'll wait until the rebase anyway.) |
75f119a
to
9e6649e
Compare
@petrochenkov Rebased atop the latest version of 145153. (All but the last two commits will go away once 145153 is merged.) |
This comment has been minimized.
This comment has been minimized.
I meant after #145153 is merged, the github interface makes reviewing stacked PRs quite inconvenient, so I basically never look at them. |
9e6649e
to
aa4b01e
Compare
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
This handles various kinds of errors, but does not allow applying the derive yet. This adds the feature gate `macro_derive`.
Add infrastructure to apply a derive macro to arguments, consuming and returning a `TokenTree` only. Handle `SyntaxExtensionKind::MacroRules` when expanding a derive, if the macro's kinds support derive. Add tests covering various cases of `macro_rules` derives.
aa4b01e
to
a9f6032
Compare
The job Click to see the possible cause of the failure (guessed by this bot)
|
@@ -70,7 +70,7 @@ expand_invalid_fragment_specifier = | |||
invalid fragment specifier `{$fragment}` | |||
.help = {$help} | |||
expand_macro_args_bad_delim = macro attribute argument matchers require parentheses | |||
expand_macro_args_bad_delim = macro `{$rule_kw}` argument matchers require parentheses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expand_macro_args_bad_delim = macro `{$rule_kw}` argument matchers require parentheses | |
expand_macro_args_bad_delim = `{$rule_kw}` macro argument matchers require parentheses |
Nit: the current wording reads weirdly.
Probably because of this FIXME in expand.rs // FIXME: Consider using the derive resolutions (`_exts`)
// instead of enqueuing the derives to be resolved again later. I don't think it's too important to fix, identically looking diagnostics are not shown to users anyway (UI tests suite specifically disables that deduplication). It's suspicious that the |
This is a draft for review, and should not be merged yet.
This is layered atop #145153 , and has
only two additional commits atop that. The first handles parsing and provides a
test for various parse errors. The second implements expansion and handles
application.
This implements RFC 3698, "Declarative (
macro_rules!
) derive macros".Tracking issue: #143549
This has one remaining issue, which I could use some help debugging: in
tests/ui/macros/macro-rules-derive-error.rs
, the diagnostics forderive(fn_only)
(for afn_only
with noderive
rules) andderive(ForwardReferencedDerive)
both get emitted twice, as a duplicatediagnostic.
From what I can tell via adding some debugging code,
unresolved_macro_suggestions
is getting called twice fromfinalize_macro_resolutions
for each of them, becauseself.single_segment_macro_resolutions
has two entries for the macro, with twodifferent
parent_scope
values. I'm not clear on why that happened; it doesn'thappen with the equivalent code using attrs.
I'd welcome any suggestions for fixing this.